import { _decorator, Component, Node, Vec3 } from 'cc';
const { ccclass, property } = _decorator;

const _pos = new Vec3();

/* used for perspective ctrl */
@ccclass('PersCtrl')
export class PersCtrl extends Component {
    onEnable() {
      
        this.updateScale();
    
        this.node.on(Node.EventType.TRANSFORM_CHANGED,(type)=>{
            if(type&Node.TransformBit.POSITION){
                this.updateScale();
            }
        })

    }
    updateScale(){

        this.node.getPosition(_pos);
        let scaleY = 1-(_pos.y+1334*0.5)*0.32/1334+0.1;
        scaleY = Math.min(scaleY,1);
        this.node.setScale(1.05,scaleY);

    }
}

